package com.javaAdmin.server;

import com.javaAdmin.mapper.StudentMapper;
import com.javaAdmin.model.Student;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class RestfulStudentServer {

    @Resource
    private StudentMapper studentMapper;

    public void save(Student student) {
        student.setCreateTime(new Date());
        student.setUpdateTime(new Date());
        studentMapper.save(student);
    }

    public void updateById(Student student) {
        student.setUpdateTime(new Date());
        studentMapper.update(student);
    }

    public List<Student> list() {
        return studentMapper.list();
    }

    public void deleteById(Integer id) {
        studentMapper.deleteById(id);
    }

    @Cacheable(cacheNames = "student", unless = "#result==null", key = "#id")
    public Student getInfoById(Integer id) {
       return studentMapper.getInfoById(id);
    }

//    public void list() {
//
//        studentMapper.list();
//        return null;
//    }

}
